package com.hoyue.attendance.service.Impl;

import com.hoyue.attendance.bean.AttendanceVo;
import com.hoyue.attendance.service.AttendanceService;
import com.hoyue.attendance.bean.Attendance;
import com.hoyue.attendance.dao.AttendanceMapper;
import com.hoyue.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * @author zhouyong
 * @date 2019/8/20 21:00
 */
@Service
public class AttendanceImpl implements AttendanceService {

    @Autowired
    private AttendanceMapper attendanceMapper;


    /**
     * 新增考勤
     * @param
     */
    @Override
    public void addAttence(Integer id, Integer studentid, Integer teachingid, Integer state,
                           Integer typ, String starttime, Integer code, String endtime) {
        // 将string转成date
        Date startTime = DateUtils.getStrToDate(starttime);
        Date endTime = DateUtils.getStrToDate(endtime);
        System.out.println(startTime + " ---- " + endTime);
        Attendance attendance = new Attendance(id,studentid,teachingid,state,typ,startTime,code,endTime);
        attendanceMapper.insert(attendance);
    }


    /**
     * 查询所有学生
     * @return
     */
    @Override
    public List<AttendanceVo> selectAll(AttendanceVo attendanceVo) {
        List<AttendanceVo> list = attendanceMapper.selectStudent(attendanceVo);
        return list;
    }

    /**
     * 根据老师姓名模糊查询签到信息
     * @param attendanceVo
     * @return
     */
    @Override
    public List<AttendanceVo> checkMessage(AttendanceVo attendanceVo) {
        return attendanceMapper.checkMessage(attendanceVo);
    }


    /**
     * 查询教师和课程
     * @return
     */
    @Override
    public List<AttendanceVo> selectCourseAnduser(AttendanceVo attendanceVo) {
        List<AttendanceVo> list = attendanceMapper.selectCoAnduser(attendanceVo);
        return list;
    }

    /**
     * 查询学生签到
     * @return
     */
    @Override
    public Integer attendIn(AttendanceVo attendanceVo) {
        Integer count = attendanceMapper.attendIn(attendanceVo);
        return count;
    }


    /**
     * 根据id查询学生信息
     * @param id
     * @return
     */
    @Override
    public List<AttendanceVo> selectStudentMess(Integer id) {
        List<AttendanceVo> list  = attendanceMapper.selectStudentMess(id);
        return list;
    }


    /**
     * 更新学生签到信息
     * @param attendanceVo
     * @return
     */
    @Override
    public int updateStudent(AttendanceVo attendanceVo) {
        int count = attendanceMapper.updateStudent(attendanceVo);
        return count;
    }
}
